package com.tpsoft.controller;

import java.util.Collection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HomeController {

    private static final Logger LOGGER = LoggerFactory.getLogger(HomeController.class);

    @RequestMapping("/home")
    public String getHomePage(Model model) {
        LOGGER.debug("Getting home page");
        model.addAttribute("roles", SecurityContextHolder.getContext().getAuthentication().getAuthorities());
        return "home";
    }
    @RequestMapping(value="/adminPage")
    @ResponseBody
    public String getAdminPaget(Model model){
        model.addAttribute("roles", SecurityContextHolder.getContext().getAuthentication().getAuthorities());
    	return "/adminPage";
    }
    @RequestMapping(value = "/denied")
    public String denied(Model model) {
      model.addAttribute("message", "抱歉您权限不足");
      return "/denied";
    }

}
